using AduSkin.Controls.Helper;
using System.Drawing;
using System.Windows;

namespace AduSkin.Themes.Metro
{
   /// <summary>
   /// AduMessageBoxWindow.xaml 的交互逻辑
   /// </summary>
   internal partial class AduMessageBoxWindow : Window
   {
      internal string Caption
      {
         get
         {
            return Win_Title.Text;
         }
         set
         {
            Win_Title.Text = value;
         }
      }

      internal string Message
      {
         get
         {
            return TextBlock_Message.Text;
         }
         set
         {
            TextBlock_Message.Text = value;
         }
      }

      internal string OkButtonText
      {
         get
         {
            return Label_Ok.Content.ToString();
         }
         set
         {
            Label_Ok.Content = value.TryAddKeyboardAccellerator();
         }
      }

      internal string CancelButtonText
      {
         get
         {
            return Label_Cancel.Content.ToString();
         }
         set
         {
            Label_Cancel.Content = value.TryAddKeyboardAccellerator();
         }
      }

      internal string YesButtonText
      {
         get
         {
            return Label_Yes.Content.ToString();
         }
         set
         {
            Label_Yes.Content = value.TryAddKeyboardAccellerator();
         }
      }

      internal string NoButtonText
      {
         get
         {
            return Label_No.Content.ToString();
         }
         set
         {
            Label_No.Content = value.TryAddKeyboardAccellerator();
         }
      }

      public MessageBoxResult Result { get; set; }

      internal AduMessageBoxWindow(string message)
      {
         InitializeComponent();

         Message = message;
         Image_MessageBox.Visibility = System.Windows.Visibility.Collapsed;
         DisplayButtons(MessageBoxButton.OK);
      }

      internal AduMessageBoxWindow(string message, string caption)
      {
         InitializeComponent();

         Message = message;
         Caption = caption;
         Image_MessageBox.Visibility = System.Windows.Visibility.Collapsed;
         DisplayButtons(MessageBoxButton.OK);
      }

      internal AduMessageBoxWindow(string message, string caption, MessageBoxButton button)
      {
         InitializeComponent();

         Message = message;
         Caption = caption;
         Image_MessageBox.Visibility = System.Windows.Visibility.Collapsed;

         DisplayButtons(button);
      }

      internal AduMessageBoxWindow(string message, string caption, MessageBoxImage image)
      {
         InitializeComponent();

         Message = message;
         Caption = caption;
         DisplayImage(image);
         DisplayButtons(MessageBoxButton.OK);
      }

      internal AduMessageBoxWindow(string message, string caption, MessageBoxButton button, MessageBoxImage image)
      {
         InitializeComponent();

         Message = message;
         Caption = caption;
         Image_MessageBox.Visibility = System.Windows.Visibility.Collapsed;

         DisplayButtons(button);
         DisplayImage(image);
      }

      private void DisplayButtons(MessageBoxButton button)
      {
         switch (button)
         {
            case MessageBoxButton.OKCancel:
               // Hide all but OK, Cancel
               Button_OK.Visibility = System.Windows.Visibility.Visible;
               Button_OK.Focus();
               Button_Cancel.Visibility = System.Windows.Visibility.Visible;

               Button_Yes.Visibility = System.Windows.Visibility.Collapsed;
               Button_No.Visibility = System.Windows.Visibility.Collapsed;
               break;
            case MessageBoxButton.YesNo:
               // Hide all but Yes, No
               Button_Yes.Visibility = System.Windows.Visibility.Visible;
               Button_Yes.Focus();
               Button_No.Visibility = System.Windows.Visibility.Visible;

               Button_OK.Visibility = System.Windows.Visibility.Collapsed;
               Button_Cancel.Visibility = System.Windows.Visibility.Collapsed;
               break;
            case MessageBoxButton.YesNoCancel:
               // Hide only OK
               Button_Yes.Visibility = System.Windows.Visibility.Visible;
               Button_Yes.Focus();
               Button_No.Visibility = System.Windows.Visibility.Visible;
               Button_Cancel.Visibility = System.Windows.Visibility.Visible;

               Button_OK.Visibility = System.Windows.Visibility.Collapsed;
               break;
            default:
               // Hide all but OK
               Button_OK.Visibility = System.Windows.Visibility.Visible;
               Button_OK.Focus();

               Button_Yes.Visibility = System.Windows.Visibility.Collapsed;
               Button_No.Visibility = System.Windows.Visibility.Collapsed;
               Button_Cancel.Visibility = System.Windows.Visibility.Collapsed;
               break;
         }
      }

      private void DisplayImage(MessageBoxImage image)
      {
         Icon icon;

         switch (image)
         {
            case MessageBoxImage.Exclamation:       // Enumeration value 48 - also covers "Warning"
               icon = SystemIcons.Exclamation;
               break;
            case MessageBoxImage.Error:             // Enumeration value 16, also covers "Hand" and "Stop"
               icon = SystemIcons.Hand;
               break;
            case MessageBoxImage.Information:       // Enumeration value 64 - also covers "Asterisk"
               icon = SystemIcons.Information;
               break;
            case MessageBoxImage.Question:
               icon = SystemIcons.Question;
               break;
            default:
               icon = SystemIcons.Information;
               break;
         }

         Image_MessageBox.Source = icon.ToImageSource();
         Image_MessageBox.Visibility = System.Windows.Visibility.Visible;
      }

      private void Button_OK_Click(object sender, RoutedEventArgs e)
      {
         Result = MessageBoxResult.OK;
         Close();
      }

      private void Button_Cancel_Click(object sender, RoutedEventArgs e)
      {
         Result = MessageBoxResult.Cancel;
         Close();
      }

      private void Button_Yes_Click(object sender, RoutedEventArgs e)
      {
         Result = MessageBoxResult.Yes;
         Close();
      }

      private void Button_No_Click(object sender, RoutedEventArgs e)
      {
         Result = MessageBoxResult.No;
         Close();
      }

      private void btnClose_Click(object sender, RoutedEventArgs e)
      {
         Close();
      }

      private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
      {
         this.DragMove();
      }
   }
}
